<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest as FRequest;
use Illuminate\Validation\ValidationException;

class FormRequest extends FRequest
{
    /**
     * @throws ValidationException
     */
    public function validated($key = null, $default = null)
    {
        $data = data_get($this->validator->validated(), $key, $default);
        foreach ($data as $k => $v) {
            if ($v === null || $v === '' || $v === []) {
                unset($data[$k]);
            }
        }
        return $data;
    }

    protected function pageRules (): array
    {
        return [
            'page' => 'nullable|integer',
            'pageSize' => 'nullable|integer|in:10,20,50,100,200,500'
        ];
    }
}
